package com.zys.el.user.controller;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.zys.el.core.controller.BaseController;
import com.zys.el.core.po.ResponseBean;
import com.zys.el.user.config.po.Show;
import com.zys.el.user.config.po.Start;
import com.zys.el.user.po.FieldMenu;
import com.zys.el.user.po.Note;
import com.zys.el.user.po.User;
import com.zys.el.user.service.IFieldMenuService;
import com.zys.el.user.service.IFieldService;
import com.zys.el.user.service.INoteService;
import com.zys.el.user.service.IUserService;
import com.zys.el.user.util.FPGrowth.Myfptree2;
import com.zys.el.user.util.TFIDF.TF_IDF;
import com.zys.el.user.util.TFIDF.Word;
import com.zys.el.user.util.TempTimesUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Slf4j
@RestController
@RequestMapping(value = "/user")
@CrossOrigin
public class UserController extends BaseController<IUserService, User> {

    @Autowired
    IFieldService FiledService;
    @Autowired
    INoteService NoteService;
    @Autowired
    private IFieldMenuService fieldMenuService;
    @Autowired
    private Myfptree2 myfptree;
    @Autowired
    private TF_IDF tf_idf;
    @Autowired
    private IUserService userService;
    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping("/list/batch_id")
    public ResponseBean getUserListByBatchId(@RequestParam List<Long> ids){
        log.info(String.valueOf(ids));
        HashMap<Long, User> map = new HashMap<>();
        for (Long id : ids) {
            map.put(id, userService.getById(id));
        }
        log.info("!!!!!!!!=>{}!!!!!", map);
        return new ResponseBean(JSON.toJSONString(map));
    }

    /*删除*/
    @GetMapping("/tiem")
    public List<List<String>> getTime() {
        TempTimesUtils t = new TempTimesUtils();
        return t.TimeList();
    }

    @GetMapping("/field/{id}")
    public String[] getUserField(@PathVariable Long id) {
        User user = new User();
        user.setFieldMenuId(id);
        Long[] longs = service.selectMenuByUser(user);
        String[] strings = FiledService.selectUserFieldById(longs);
        return strings;
    }

    @GetMapping("/fans/count/{id}")
    public Integer getFansCount(@PathVariable Long id) {
        User user = new User();
        user.setFansMenuId(id);
        Integer integer = service.selectCountFans(user);
        return integer;
    }

    @GetMapping("/follow/count/{id}")
    public Integer getFollowCount(@PathVariable Long id) {
        User user = new User();
        user.setFollowMenuId(id);
        Integer integer = service.selectCountFollow(user);
        return integer;
    }

    @GetMapping("/data/{id}")
    public ResponseBean getUserData(@PathVariable Long id) throws JsonProcessingException {
        ResponseBean responseBean = new ResponseBean();

//        String o = (String) redisTemplate.opsForValue().get("ND" + id);
//
//        if (o == null) {
            Show s = service.getUserNoteDataByUserId(id);
            responseBean.setModel(s);
//            return responseBean;
//        } else {
//            Show jsonObject = com.alibaba.fastjson2.JSON.parseObject(o, Show.class);
//            responseBean.setModel(jsonObject);
//        }
        return responseBean;
    }
}
